package cn.caplike.demo.repository.java.concurrency.synchroniz.ed;

/**
 * Description: 简单测试 synchronized
 *
 * @author LiKe
 * @date 2020-03-14 17:20:43
 */
public class SynchronizedOnClass {
    public static void main(String[] args) {
        new Capsule().m();
    }
}

class Capsule {
    private final Object o = new Object();
    private int count = 10;

    public void m() {
        // 任何线程要执行下面的代码，必须先拿到o的锁
        synchronized (o/*this*/) {
            count--;
            System.out.println(Thread.currentThread().getName() + " count = " + count);
        }
    }
}
